package com.hwzn.module.admin.service.impl;

import static com.hwzn.module.core.enums.ErrorCodeConstants.AUTH_TOKEN_ERROR;
import static com.hwzn.module.core.enums.ErrorCodeConstants.AUTH_USER_NOT_EXISTS;
import static com.hwzn.module.core.utils.ServiceExceptionUtil.exception;

import javax.annotation.Resource;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.hwzn.module.admin.service.UserService;
import com.hwzn.module.core.dos.UserDO;

/**
 * 类注释
 *
 * @author jiaobo
 * @date Created in 2024/5/15 17:30
 * @company hw
 **/
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Resource
    private UserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserDO user = userService.getUserByUsername(username);
        if (user == null) {
            throw exception(AUTH_USER_NOT_EXISTS);
        }
        return user;
    }
}
